package cn.jiyun.ai.controller;

import cn.jiyun.ai.ShopsService;
import cn.jiyun.ai.pojo.Shops;
import cn.jiyun.ai.pojo.UpdateStatusDto;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("shops")
@CrossOrigin
public class ShopsController {
    @Autowired
    ShopsService shopsService;

    @PostMapping("shopsList")
    public List<Shops> shopsList(){
        return shopsService.list();
    }

    @RequestMapping("updateStatus")
    public String updateStatus(@RequestBody UpdateStatusDto dto) {
        Integer id = dto.getId();
        if (id == null) {
            return "店铺ID不能为空";
        }
        Shops shops = shopsService.getOne(new LambdaQueryWrapper<Shops>().eq(Shops::getId, id));
        if (shops == null) {
            return "店铺ID不存在";
        }
        shops.setStatus(2);
        shopsService.updateById(shops);
        return "状态更新成功";
    }


}
